package com.neusoft.neuiotms.dcom.converter.malfunction;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.neusoft.bizcore.web.dto.AbstractConverter;
import com.neusoft.neuiotms.dcom.dto.malfunction.MalfunctionLeaderApprovalDTO;
import com.neusoft.neuiotms.dcom.model.malfunction.MalfunctionLeaderApproval;
import com.neusoft.neuiotms.dcom.repository.malfunction.MalfunctionLeaderApprovalRepository;

@Component
public class MalfunctionLeaderApprovalConverter
        extends AbstractConverter<MalfunctionLeaderApproval, MalfunctionLeaderApprovalDTO> {

    @Autowired
    private MalfunctionLeaderApprovalRepository leaderApprovalRepository;

    @Override
    public MalfunctionLeaderApproval toModel(final MalfunctionLeaderApprovalDTO dto) {

        MalfunctionLeaderApproval model;
        if (dto.isNew()) {
            model = new MalfunctionLeaderApproval();
        } else {
            model = this.leaderApprovalRepository.getOne(dto.getId());
        }

        model.setApprovalComments(dto.getApprovalComments());
        model.setTaskId(dto.getTaskId());
        model.setWorkNum(dto.getWorkNum());
        model.setOperatorCode(dto.getOperatorCode());
        model.setOperatorName(dto.getOperatorName());
        model.setWhetherAgree(dto.getWhetherAgree());
        model.setWhetherTransfer(dto.getWhetherTransfer());
        model.setSecondOperatorCode(dto.getSecondOperatorCode());
        model.setSecondOperatorName(dto.getSecondOperatorName());
        model.setTransferSecondlineReason(dto.getTransferSecondlineReason());
        model.setHelperEngineerCode(dto.getHelperEngineerCode());
        model.setHelperEngineerName(dto.getHelperEngineerName());
        model.setFaultLevel(dto.getFaultLevel());

        return model;
    }

    @Override
    public MalfunctionLeaderApprovalDTO toDTO(final MalfunctionLeaderApproval model, final boolean forListView) {

        final MalfunctionLeaderApprovalDTO dto = new MalfunctionLeaderApprovalDTO();
        dto.setId(model.getId());
        dto.setApprovalComments(model.getApprovalComments());
        dto.setTaskId(model.getTaskId());
        dto.setWorkNum(model.getWorkNum());
        dto.setOperatorCode(model.getOperatorCode());
        dto.setOperatorName(model.getOperatorName());
        dto.setWhetherAgree(model.getWhetherAgree());
        dto.setWhetherTransfer(model.getWhetherTransfer());
        dto.setSecondOperatorCode(model.getSecondOperatorCode());
        dto.setSecondOperatorName(model.getSecondOperatorName());
        dto.setTransferSecondlineReason(model.getTransferSecondlineReason());
        dto.setHelperEngineerCode(model.getHelperEngineerCode());
        dto.setHelperEngineerName(model.getHelperEngineerName());
        dto.setFaultLevel(model.getFaultLevel());
        return dto;
    }

}
